/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.actions.client;

import com.myapp.MyApp;
import com.mydatastore.ClientDataStore;
import com.mydatastore.mysql.client.ClientDataStoreMySQL;
import com.mydatastore.DataStoreException;
import com.myweb.WebAction;
import com.myweb.WebException;
import com.myweb.WebRequest;
import com.myweb.WebResponse;
import com.myweb.annotation.Action;

/**
 *
 * @author DTIT
 */
@Action(url = "clients/get")
public class GetClient implements WebAction {

  private int id;

  @Override
  public void validate(WebRequest request) throws WebException {
    id = request.getIntegerNN("id");
  }

  @Override
  public void process(WebRequest req, WebResponse res) throws WebException {
    try {
      ClientDataStore ds = new ClientDataStoreMySQL(MyApp.getConnection());
      res.setResult(ds.getClientById(id));
      
    } catch (DataStoreException ex) {
      throw new WebException(ex.getMessage());
    }
  }

  @Override
  public String getRenderer() {
    return "/WEB-INF/client/detail.jsp";
  }
}
